export const CHANGE_LANGUAGE = 'change_language';
export const ADD_LANGUAGE = 'add_language';

interface IChangeLanguageAction extends Record<string, unknown> {
  type: typeof CHANGE_LANGUAGE;
  payload: 'zh' | 'en';
}
interface IAddLanguageAction extends Record<string, unknown> {
  type: typeof ADD_LANGUAGE;
  payload: { name: string; code: string };
}

export type languageActionTypes = IChangeLanguageAction | IAddLanguageAction;
// 切换
export const changeLanguageActionCreator = (languageCode: 'zh' | 'en'): IChangeLanguageAction => {
  return {
    type: CHANGE_LANGUAGE,
    payload: languageCode
  };
};

// 添加
export const addLanguageActionCreator = (name: string, code: string): IAddLanguageAction => {
  return {
    type: ADD_LANGUAGE,
    payload: { name, code }
  };
};
